/**
    [Filename]
    Purpose: [Purpose]

    @author Jason Wojcik
    @version [version]
*/

#include "CChip.h"



//constructor
CChip::CChip() {

    //turn gravity off
    Flags = ENTITY_FLAG_NONE;

    //turn off iskeydown
    IsKeyUp = true;

    //ID of chip - red or not
    ChipColor = RED;

    MaxSpeedX = 64;
    MaxSpeedY = 64;


}

//loads the image file for the player
bool CChip::OnLoad(char* File, int Width, int Height, int MaxFrames) {
    if(CEntity::OnLoad(File, Width, Height, MaxFrames) == false) {
        return false;
    }

    return true;
}

//player loop
void CChip::OnLoop() {

     if(MoveLeft == false && MoveRight == false) {
        StopMove();
    }

    //move to the left one tile if the token isn't falling
    if(MoveLeft) {
        //only move if KeyUp Flag set, no Y motion, and X > 2*TILE (LBound)
        if(!IsKeyUp && Y < TILE_SIZE && X > 2 * TILE_SIZE){
            X -= TILE_SIZE;
        }
        IsKeyUp = true;
    }else

    //move to the right
    if(MoveRight) {
        //only move if KeyUp Flag set, no Y motion, and X < 8*TILE (RBound)
        if(!IsKeyUp && Y < TILE_SIZE && X < 8 * TILE_SIZE){
            X += TILE_SIZE;
        }
        IsKeyUp = true;
    }

    if(Flags & ENTITY_FLAG_GRAVITY) {
        AccelY = Gravity;
    }

    SpeedX += AccelX * CFPS::FPSControl.GetSpeedFactor();
    SpeedY += AccelY * CFPS::FPSControl.GetSpeedFactor();

    if(SpeedX > MaxSpeedX)  SpeedX =  MaxSpeedX;
    if(SpeedX < -MaxSpeedX) SpeedX = -MaxSpeedX;
    if(SpeedY > MaxSpeedY)  SpeedY =  MaxSpeedY;
    if(SpeedY < -MaxSpeedY) SpeedY = -MaxSpeedY;

    OnMove(SpeedX, SpeedY);

}

void CChip::OnRender(SDL_Surface* Surf_Display) {
    CEntity::OnRender(Surf_Display);
}

void CChip::OnCleanup() {
    CEntity::OnCleanup();
}

void CChip::OnAnimate() {
    CEntity::OnAnimate();
}

bool CChip::OnCollision(CEntity* Entity) {
    return true;
}
